package item.inkcloud.shopservice.controller;

import com.alibaba.fastjson.JSONObject;
import item.inkcloud.shopservice.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

@RestController
@RequestMapping("/shop")
public class ShopController {

    @Autowired
    private ProductService productService;

    @PostMapping("/order")
    public HashMap order(@RequestParam("userid") String userid, @RequestBody JSONObject jsonPara){

        Object productName = jsonPara.get("productName");

        int status = productService.order(userid,(String)productName);
        HashMap<String,Object> resultMap = new HashMap<>();

          resultMap.put("status",status);
          return  resultMap;



    }

    //获取资源列表
    @GetMapping("productList")
    public HashMap productList(){
        try {
            int status;
            status = 1;
            HashMap<String, Object> resultMap = new HashMap<>();
            resultMap.put("status", status);
            resultMap.put("data", productService.productList());
            return resultMap;
        }catch (Exception e) {
            int status;
            status = 0;
            HashMap<String, Object> resultMap = new HashMap<>();
            resultMap.put("status", status);
            return resultMap;
        }

    }



}


